<html>

<head>
    <script>
        var dojoConfig = {
            paths: {
                "olesk": "/olesk"
            }
        };
    </script>

    <script type="text/javascript"
            src="/dj/dojo/dojo.js"
            data-dojo-config="isDebug:true">
    </script>

    <script type="text/javascript">

    require(["olesk/widgets/TwitterFeed/TwitterFeedWidget",
            "doh",
            "dojo/query",
            "dojo/dom-class",
            "dojo/dom",
            "dojo/dom-construct",
            "dojo/_base/lang",
            "dojo/domReady!"], 
            function (TwitterFeedWidget, doh, query, domClass, dom, domConstruct, lang) {
    	
    	var base_test_obj_factory = function () {
    		return {
    			setUp: function () {
                    domConstruct.empty("arena");
                },
                tearDown: function () {
                    domConstruct.empty("arena");
                }   
    		};
    	};
    	doh.register("init_tests", [
			lang.mixin(base_test_obj_factory(), {
			    name: "empty_widget",
			    runTest: function () {
			        var twitterWidget =  new TwitterFeedWidget();
			        twitterWidget.placeAt(dom.byId('arena'));
			        doh.assertEqual(0, query('.b-twitter-message').length);
			    }
			})                              
    	]);
    	doh.register("push_twits_tests", [
    	    lang.mixin(base_test_obj_factory(), {
    	    	name: "push_twits_while_dettached_from_dom",
                runTest: function () {
                    var twitterWidget =  new TwitterFeedWidget();
                    twitterWidget.pushTwit({
                        text: "trololo",
                        time: "Wed Apr 11 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "ololo",
                        time: "Wed Apr 12 17:50:17 +0000 2012"
                    });
                    twitterWidget.placeAt(dom.byId('arena'));
                    
                    doh.assertEqual("trololo", 
                            query('.b-twitter-message__text')[1].innerHTML);
                    doh.assertEqual("Wed Apr 11 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[1].innerHTML);
                    doh.assertEqual("ololo", 
                            query('.b-twitter-message__text')[0].innerHTML);
                    doh.assertEqual("Wed Apr 12 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[0].innerHTML);
                }
            }),
            lang.mixin(base_test_obj_factory(), {
            	name: "push_twit_while_attached_to_dom",
                runTest: function () {
                    var twitterWidget =  new TwitterFeedWidget();
                    twitterWidget.placeAt(dom.byId('arena'));
                    twitterWidget.pushTwit({
                        text: "trololo",
                        time: "Wed Apr 11 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "ololo",
                        time: "Wed Apr 12 17:50:17 +0000 2012"
                    });
                    twitterWidget.placeAt(dom.byId('arena'));
                    
                    doh.assertEqual("trololo", 
                            query('.b-twitter-message__text')[1].innerHTML);
                    doh.assertEqual("Wed Apr 11 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[1].innerHTML);
                    doh.assertEqual("ololo", 
                            query('.b-twitter-message__text')[0].innerHTML);
                    doh.assertEqual("Wed Apr 12 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[0].innerHTML);
                }
            })
    	]);
    	doh.register("pop_twit_tests", [
			lang.mixin(base_test_obj_factory(), {
			    name: "pop_twit_while_dettached_from_dom",
			    runTest: function () {
			    	var twitterWidget =  new TwitterFeedWidget();
			    	twitterWidget.pushTwit({
                        text: "trololo",
                        time: "Wed Apr 11 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "ololo",
                        time: "Wed Apr 12 17:50:17 +0000 2012"
                    });
                    var popedTwit = twitterWidget.popTwit()
                    twitterWidget.placeAt(dom.byId('arena'));
                    
                    doh.assertEqual("ololo", 
                            query('.b-twitter-message__text')[0].innerHTML);
                    doh.assertEqual("Wed Apr 12 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[0].innerHTML);
                    doh.assertEqual("trololo", popedTwit.text);
                    doh.assertEqual("Wed Apr 11 17:50:17 +0000 2012", popedTwit.time);
			    }
			}),
			lang.mixin(base_test_obj_factory(), {
                name: "pop_twit_while_attached_to_dom",
                runTest: function () {
                    var twitterWidget =  new TwitterFeedWidget();
                    twitterWidget.placeAt(dom.byId('arena'));
                    twitterWidget.pushTwit({
                        text: "trololo",
                        time: "Wed Apr 11 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "ololo",
                        time: "Wed Apr 12 17:50:17 +0000 2012"
                    });
                    var popedTwit = twitterWidget.popTwit()
                                        
                    doh.assertEqual("ololo", 
                            query('.b-twitter-message__text')[0].innerHTML);
                    doh.assertEqual("Wed Apr 12 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[0].innerHTML);
                    doh.assertEqual("trololo", popedTwit.text);
                    doh.assertEqual("Wed Apr 11 17:50:17 +0000 2012", popedTwit.time);
                }
            })
      	]);
    	doh.register("capasity_tests", [
            lang.mixin(base_test_obj_factory(), {
                name: "test_capasity_while_dettached_from_dom",
                runTest: function () {
                    var twitterWidget =  new TwitterFeedWidget({
                    	capasity: 2
                    });
                    twitterWidget.pushTwit({
                        text: "trololo",
                        time: "Wed Apr 11 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "ololo",
                        time: "Wed Apr 12 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "xolokost",
                        time: "Wed Apr 13 17:50:17 +0000 2012"
                    });
                    twitterWidget.placeAt(dom.byId('arena'));
                    
                    doh.assertEqual(2, query('.b-twitter-message').length);
                    doh.assertEqual("ololo", query('.b-twitter-message__text')[1].innerHTML);
                    doh.assertEqual("Wed Apr 12 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[1].innerHTML);
                    doh.assertEqual("xolokost", query('.b-twitter-message__text')[0].innerHTML);
                    doh.assertEqual("Wed Apr 13 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[0].innerHTML);
                }
            }),
            lang.mixin(base_test_obj_factory(), {
                name: "test_capasity_while_attached_to_dom",
                runTest: function () {
                	var twitterWidget =  new TwitterFeedWidget({
                        capasity: 2
                    });
                    twitterWidget.placeAt(dom.byId('arena'));
                    twitterWidget.pushTwit({
                        text: "trololo",
                        time: "Wed Apr 11 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "ololo",
                        time: "Wed Apr 12 17:50:17 +0000 2012"
                    });
                    twitterWidget.pushTwit({
                        text: "xolokost",
                        time: "Wed Apr 13 17:50:17 +0000 2012"
                    });
                    
                    doh.assertEqual(2, query('.b-twitter-message').length);
                    doh.assertEqual("ololo", query('.b-twitter-message__text')[1].innerHTML);
                    doh.assertEqual("Wed Apr 12 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[1].innerHTML);
                    doh.assertEqual("xolokost", query('.b-twitter-message__text')[0].innerHTML);
                    doh.assertEqual("Wed Apr 13 17:50:17 +0000 2012", 
                            query('.b-twitter-message__time')[0].innerHTML);
                }
            })
        ]);
      
        doh.run();
    });
    </script>
</head>
<body>
    <div id="arena"></div>
</body>
</html>
